package ru.compft.common.data.acl;

import ru.compft.common.data.meta.acl.AclObjectIdentityTableMeta;

import javax.persistence.*;
import java.io.Serializable;

/**
 * Created with IntelliJ IDEA.
 * User: VVasiliev
 * Date: 01.11.12
 * Time: 12:00
 * <p/>
 * Класс представляющий объект "Идентификаторы объектов в ACL"
 * <p/>
 * CREATE TABLE IF NOT EXISTS ACL_OBJECT_IDENTITY (
 * ID INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
 * OBJECT_ID_CLASS INT(20) NOT NULL,
 * OBJECT_ID_IDENTITY INT(20) NOT NULL,
 * PARENT_OBJECT INT(20) DEFAULT NULL,
 * OWNER_SID INT(20) DEFAULT NULL,
 * ENTRIES_INHERITING VARCHAR(1) NOT NULL,
 * CONSTRAINT UNIQUE_UK_3 UNIQUE(OBJECT_ID_CLASS,OBJECT_ID_IDENTITY),
 * CONSTRAINT FOREIGN_FK_1 FOREIGN KEY(PARENT_OBJECT) REFERENCES ACL_OBJECT_IDENTITY(ID),
 * CONSTRAINT FOREIGN_FK_2 FOREIGN KEY(OBJECT_ID_CLASS) REFERENCES ACL_CLASS(ID),
 * CONSTRAINT FOREIGN_FK_3 FOREIGN KEY(OWNER_SID) REFERENCES ACL_SID(ID)
 * )
 */
@Entity
@Table(name = AclObjectIdentityTableMeta.TABLE_NAME, uniqueConstraints = {
        @UniqueConstraint(columnNames = {AclObjectIdentityTableMeta.OBJECT_ID_CLASS, AclObjectIdentityTableMeta.OBJECT_ID_IDENTITY})})
public class AclObjectIdentity implements Serializable {
    private static final long serialVersionUID = -8684540106017181974L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = AclObjectIdentityTableMeta.ID, unique = true, nullable = false)
    private Long id;

    @Column(name = AclObjectIdentityTableMeta.OBJECT_ID_CLASS, nullable = false, length = 20)
    private Long objectIdClass;

    @Column(name = AclObjectIdentityTableMeta.OBJECT_ID_IDENTITY, nullable = false, length = 20)
    private Long objectIdIdentity;

    @Column(name = AclObjectIdentityTableMeta.PARENT_OBJECT, length = 20)
    private Long parentObject;

    @Column(name = AclObjectIdentityTableMeta.OWNER_SID, length = 20)
    private Long ownerSid;

    @Column(name = AclObjectIdentityTableMeta.ENTRIES_INHERITING, nullable = false, length = 1)
    private String entriesInheriting;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = AclObjectIdentityTableMeta.OBJECT_ID_CLASS, insertable = false, updatable = false)
    private AclClass aclClass;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = AclObjectIdentityTableMeta.PARENT_OBJECT, insertable = false, updatable = false)
    private AclObjectIdentity parentAclObjectIdentity;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = AclObjectIdentityTableMeta.OWNER_SID, insertable = false, updatable = false)
    private AclSid aclSid;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getObjectIdClass() {
        return objectIdClass;
    }

    public void setObjectIdClass(Long objectIdClass) {
        this.objectIdClass = objectIdClass;
    }

    public Long getObjectIdIdentity() {
        return objectIdIdentity;
    }

    public void setObjectIdIdentity(Long objectIdIdentity) {
        this.objectIdIdentity = objectIdIdentity;
    }

    public Long getParentObject() {
        return parentObject;
    }

    public void setParentObject(Long parentObject) {
        this.parentObject = parentObject;
    }

    public Long getOwnerSid() {
        return ownerSid;
    }

    public void setOwnerSid(Long ownerSid) {
        this.ownerSid = ownerSid;
    }

    public String getEntriesInheriting() {
        return entriesInheriting;
    }

    public void setEntriesInheriting(String entriesInheriting) {
        this.entriesInheriting = entriesInheriting;
    }

    public AclClass getAclClass() {
        return aclClass;
    }

    public void setAclClass(AclClass aclClass) {
        this.aclClass = aclClass;
    }

    public AclObjectIdentity getParentAclObjectIdentity() {
        return parentAclObjectIdentity;
    }

    public void setParentAclObjectIdentity(AclObjectIdentity parentAclObjectIdentity) {
        this.parentAclObjectIdentity = parentAclObjectIdentity;
    }

    public AclSid getAclSid() {
        return aclSid;
    }

    public void setAclSid(AclSid aclSid) {
        this.aclSid = aclSid;
    }
}
